package cn.edu.scau.cmi.chensixiao.javaFX;

import cn.edu.scau.cmi.chensixiao.abstractFactory.domainAbstractClass.Insurance;
import cn.edu.scau.cmi.chensixiao.abstractFactory.factory.AbstractInsuranceFactory;
import cn.edu.scau.cmi.chensixiao.abstractFactory.factory.PICCInsuranceFactory;
import cn.edu.scau.cmi.chensixiao.abstractFactory.factory.PingAnInsuranceFactory;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.image.ImageView;

public class AbstractFactoryController {
	@FXML
	private ImageView photo;
	@FXML
	private Label nameLabel;
	@FXML
	private Label idLabel;
	@FXML
	private Label companyLabel;
	@FXML
	private ChoiceBox<String> companyChoice;
	@FXML
	private Label insuranceLabel;
	@FXML
	private ChoiceBox<String> insuranceChoice;
	@FXML
	private Button messageButton;
	@FXML
	private TextArea messageText;
	@FXML
	private Label tipOfCompany;
	@FXML
	private Label tipOfInsurance;
	
	

	public void initialize() {
		
		insuranceChoice.getItems().addAll("车上人员责任险","车辆损失险","其他事故");
		companyChoice.getItems().addAll("PICC","PingAn");
		
	}
	
	public void ButtonOnClick() {
		tipOfCompany.setVisible(false);
		tipOfInsurance.setVisible(false);
		//选择公司
		AbstractInsuranceFactory Insurancefactory = null;
		String company = companyChoice.getValue();
		try {
			switch(company) {
			case"PICC": Insurancefactory = new PICCInsuranceFactory();break;
			case"PingAn": Insurancefactory = new PingAnInsuranceFactory();break;
			//default:tipOfCompany.setVisible(true);break;
			}
			
			//选择保险
			Insurance insurance = null;
			String insuranceType = insuranceChoice.getValue();
			try {
				switch(insuranceType) {
				case"车上人员责任险": insurance = Insurancefactory.creatDriverInsurance();break;
				case"车辆损失险": insurance = Insurancefactory.creatCarInsurance();break;
				case"其他事故": insurance  = Insurancefactory.creatOtherInsurance();break;
				//default:tipOfInsurance.setVisible(true);break;
				}
				
				if(insurance!=null) { 
					//Insurance insurance = insuranceFactory.getInstance();
					messageText.setText(insurance.showMessage());
				 
				}
			}catch(Exception e) {
				
				tipOfInsurance.setVisible(true);
			}
			
		
		}catch(Exception e) {

			tipOfCompany.setVisible(true);
		}
			
	}
	
}
	

